package com.definesys.smecrailtransit.module.lineCharts.adapter;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.definesys.smecrailtransit.BR;
import com.definesys.smecrailtransit.R;
import com.definesys.smecrailtransit.base.SmecBaseRecyclerViewHolder;
import com.definesys.smecrailtransit.databinding.ItemErrorEleBinding;
import com.definesys.smecrailtransit.module.lineCharts.beans.MonEleError;
import com.definesys.smecrailtransit.utils.CommonUtils;

import java.util.ArrayList;

/**
 * Created by xupeizuo on 2018/3/8.
 */

public class SmecErrorEleAdapter extends RecyclerView.Adapter<SmecBaseRecyclerViewHolder> {

    private Context context;
    private ArrayList<MonEleError> arrayList=new ArrayList<>();

    public SmecErrorEleAdapter(Context context) {
        this.context = context;
    }

    @Override
    public SmecBaseRecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ItemErrorEleBinding itemErrorEleBinding= DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.item_error_ele,parent,false);
        SmecBaseRecyclerViewHolder smecBaseRecyclerViewHolder=new SmecBaseRecyclerViewHolder(itemErrorEleBinding.getRoot());
        smecBaseRecyclerViewHolder.setViewType(viewType);
        smecBaseRecyclerViewHolder.setBinding(itemErrorEleBinding);
        return smecBaseRecyclerViewHolder;
    }

    @Override
    public void onBindViewHolder(SmecBaseRecyclerViewHolder holder, int position) {
        ItemErrorEleBinding itemErrorEleBinding=(ItemErrorEleBinding)holder.getBinding();
        itemErrorEleBinding.setVariable(BR.mleError,arrayList.get(position));
    }

    public void setArrayList(ArrayList<MonEleError> aist) {
        this.arrayList = aist;
        notifyDataSetChanged();

    }

    @Override
    public int getItemCount() {
        return arrayList.size();
    }
}
